<!DOCTYPE html>
<html lang=en>
<head>
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。 Systemd是一个系统管理守护进程、工具和库的集合，用于取代System V初始进程。Systemd的功能是用于集中管理和配置类UNIX系统。 在Linux生态系统中，Systemd被部署到了大多数的标准Linux发行版中，只有为数不多的几个发行版尚未部署。Systemd通常是所有其它守护进程的父进程，但并">
<meta property="og:type" content="article">
<meta property="og:title" content="Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。">
<meta property="og:url" content="http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/index.html">
<meta property="og:site_name" content="TmoonSite">
<meta property="og:description" content="Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。 Systemd是一个系统管理守护进程、工具和库的集合，用于取代System V初始进程。Systemd的功能是用于集中管理和配置类UNIX系统。 在Linux生态系统中，Systemd被部署到了大多数的标准Linux发行版中，只有为数不多的几个发行版尚未部署。Systemd通常是所有其它守护进程的父进程，但并">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2016-07-19T11:03:52.000Z">
<meta property="article:modified_time" content="2020-01-07T10:48:14.890Z">
<meta property="article:author" content="Tmoonlight">
<meta name="twitter:card" content="summary">
    
    
        
          
              <link rel="shortcut icon" href="/images/favicon.ico">
          
        
        
          
            <link rel="icon" type="image/png" href="/images/logo2.gif" sizes="192x192">
          
        
        
          
            <link rel="apple-touch-icon" sizes="180x180" href="/images/logo2.gif">
          
        
    
    <!-- title -->
    <title>Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。</title>
    <!-- styles -->
    
<link rel="stylesheet" href="/css/style.css">

    <!-- persian styles -->
    
      
<link rel="stylesheet" href="/css/rtl.css">

    
    <!-- rss -->
    
    
<meta name="generator" content="Hexo 4.2.0"></head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
         
          <li><a href="/">Home</a></li>
         
          <li><a href="/about/">About</a></li>
         
          <li><a href="/archives/">Writing</a></li>
         
          <li><a href="/projects_url">Projects</a></li>
        
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" href="/2016/07/25/Eclipse%E5%B8%B8%E7%94%A8%E5%BF%AB%E6%8D%B7%E9%94%AE-jack_Meng-%E5%8D%9A%E5%AE%A2%E5%9B%AD/"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" href="/2016/07/02/u3d%E9%87%8C%E5%8A%A8%E6%80%81%E5%88%9B%E5%BB%BA%E5%AF%B9%E8%B1%A1%EF%BC%8C%E9%9C%80%E8%A6%81%E4%BD%BF%E7%94%A8prefab/"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">Previous post</span>
      <span id="i-next" class="info" style="display:none;">Next post</span>
      <span id="i-top" class="info" style="display:none;">Back to top</span>
      <span id="i-share" class="info" style="display:none;">Share post</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/" target="_blank" rel="noopener"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&text=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。" target="_blank" rel="noopener"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&title=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。" target="_blank" rel="noopener"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&is_video=false&description=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。" target="_blank" rel="noopener"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。&body=Check out this article: http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&title=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。" target="_blank" rel="noopener"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&title=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。" target="_blank" rel="noopener"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&title=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。" target="_blank" rel="noopener"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&title=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。" target="_blank" rel="noopener"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&name=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。&description=" target="_blank" rel="noopener"><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://news.ycombinator.com/submitlink?u=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&t=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。" target="_blank" rel="noopener"><i class="fab fa-hacker-news " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#Systemd初体验和Systemctl基础"><span class="toc-number">1.</span> <span class="toc-text">Systemd初体验和Systemctl基础</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-首先检查你的系统中是否安装有systemd并确定当前安装的版本"><span class="toc-number">1.1.</span> <span class="toc-text">1. 首先检查你的系统中是否安装有systemd并确定当前安装的版本</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-检查systemd和systemctl的二进制文件和库文件的安装位置"><span class="toc-number">1.2.</span> <span class="toc-text">2. 检查systemd和systemctl的二进制文件和库文件的安装位置</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-检查systemd是否运行"><span class="toc-number">1.3.</span> <span class="toc-text">3. 检查systemd是否运行</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-分析systemd启动进程"><span class="toc-number">1.4.</span> <span class="toc-text">4. 分析systemd启动进程</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-分析启动时各个进程花费的时间"><span class="toc-number">1.5.</span> <span class="toc-text">5. 分析启动时各个进程花费的时间</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#6-分析启动时的关键链"><span class="toc-number">1.6.</span> <span class="toc-text">6. 分析启动时的关键链</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#7-列出所有可用单元"><span class="toc-number">1.7.</span> <span class="toc-text">7. 列出所有可用单元</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#8-列出所有运行中单元"><span class="toc-number">1.8.</span> <span class="toc-text">8. 列出所有运行中单元</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#9-列出所有失败单元"><span class="toc-number">1.9.</span> <span class="toc-text">9. 列出所有失败单元</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#10-检查某个单元（如-cron-service）是否启用"><span class="toc-number">1.10.</span> <span class="toc-text">10. 检查某个单元（如 cron.service）是否启用</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#11-检查某个单元或服务是否运行"><span class="toc-number">1.11.</span> <span class="toc-text">11. 检查某个单元或服务是否运行</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#使用Systemctl控制并管理服务"><span class="toc-number">2.</span> <span class="toc-text">使用Systemctl控制并管理服务</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#12-列出所有服务（包括启用的和禁用的）"><span class="toc-number">2.1.</span> <span class="toc-text">12. 列出所有服务（包括启用的和禁用的）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#13-Linux中如何启动、重启、停止、重载服务以及检查服务（如-httpd-service）状态"><span class="toc-number">2.2.</span> <span class="toc-text">13. Linux中如何启动、重启、停止、重载服务以及检查服务（如 httpd.service）状态</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#14-如何激活服务并在启动时启用或禁用服务（即系统启动时自动启动服务）"><span class="toc-number">2.3.</span> <span class="toc-text">14. 如何激活服务并在启动时启用或禁用服务（即系统启动时自动启动服务）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#15-如何屏蔽（让它不能启动）或显示服务（如-httpd-service）"><span class="toc-number">2.4.</span> <span class="toc-text">15. 如何屏蔽（让它不能启动）或显示服务（如 httpd.service）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#16-使用systemctl命令杀死服务"><span class="toc-number">2.5.</span> <span class="toc-text">16. 使用systemctl命令杀死服务</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#使用Systemctl控制并管理挂载点"><span class="toc-number">3.</span> <span class="toc-text">使用Systemctl控制并管理挂载点</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#17-列出所有系统挂载点"><span class="toc-number">3.1.</span> <span class="toc-text">17. 列出所有系统挂载点</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#18-挂载、卸载、重新挂载、重载系统挂载点并检查系统中挂载点状态"><span class="toc-number">3.2.</span> <span class="toc-text">18. 挂载、卸载、重新挂载、重载系统挂载点并检查系统中挂载点状态</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#19-在启动时激活、启用或禁用挂载点（系统启动时自动挂载）"><span class="toc-number">3.3.</span> <span class="toc-text">19. 在启动时激活、启用或禁用挂载点（系统启动时自动挂载）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#20-在Linux中屏蔽（让它不能启用）或可见挂载点"><span class="toc-number">3.4.</span> <span class="toc-text">20. 在Linux中屏蔽（让它不能启用）或可见挂载点</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#使用Systemctl控制并管理套接口"><span class="toc-number">4.</span> <span class="toc-text">使用Systemctl控制并管理套接口</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#21-列出所有可用系统套接口"><span class="toc-number">4.1.</span> <span class="toc-text">21. 列出所有可用系统套接口</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#22-在Linux中启动、重启、停止、重载套接口并检查其状态"><span class="toc-number">4.2.</span> <span class="toc-text">22. 在Linux中启动、重启、停止、重载套接口并检查其状态</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#23-在启动时激活套接口，并启用或禁用它（系统启动时自启动）"><span class="toc-number">4.3.</span> <span class="toc-text">23. 在启动时激活套接口，并启用或禁用它（系统启动时自启动）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#24-屏蔽（使它不能启动）或显示套接口"><span class="toc-number">4.4.</span> <span class="toc-text">24. 屏蔽（使它不能启动）或显示套接口</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#服务的CPU利用率（分配额）"><span class="toc-number">5.</span> <span class="toc-text">服务的CPU利用率（分配额）</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#25-获取当前某个服务的CPU分配额（如httpd）"><span class="toc-number">5.1.</span> <span class="toc-text">25. 获取当前某个服务的CPU分配额（如httpd）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#26-将某个服务（httpd-service）的CPU分配份额限制为2000-CPUShares"><span class="toc-number">5.2.</span> <span class="toc-text">26. 将某个服务（httpd.service）的CPU分配份额限制为2000 CPUShares&#x2F;</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#27-检查某个服务的所有配置细节"><span class="toc-number">5.3.</span> <span class="toc-text">27. 检查某个服务的所有配置细节</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#28-分析某个服务（httpd）的关键链"><span class="toc-number">5.4.</span> <span class="toc-text">28. 分析某个服务（httpd）的关键链</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#29-获取某个服务（httpd）的依赖性列表"><span class="toc-number">5.5.</span> <span class="toc-text">29. 获取某个服务（httpd）的依赖性列表</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#30-按等级列出控制组"><span class="toc-number">5.6.</span> <span class="toc-text">30. 按等级列出控制组</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#31-按CPU、内存、输入和输出列出控制组"><span class="toc-number">5.7.</span> <span class="toc-text">31. 按CPU、内存、输入和输出列出控制组</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#控制系统运行等级"><span class="toc-number">6.</span> <span class="toc-text">控制系统运行等级</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#32-启动系统救援模式"><span class="toc-number">6.1.</span> <span class="toc-text">32. 启动系统救援模式</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#33-进入紧急模式"><span class="toc-number">6.2.</span> <span class="toc-text">33. 进入紧急模式</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#34-列出当前使用的运行等级"><span class="toc-number">6.3.</span> <span class="toc-text">34. 列出当前使用的运行等级</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#35-启动运行等级5，即图形模式"><span class="toc-number">6.4.</span> <span class="toc-text">35. 启动运行等级5，即图形模式</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#36-启动运行等级3，即多用户模式（命令行）"><span class="toc-number">6.5.</span> <span class="toc-text">36. 启动运行等级3，即多用户模式（命令行）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#36-设置多用户模式或图形模式为默认运行等级"><span class="toc-number">6.6.</span> <span class="toc-text">36. 设置多用户模式或图形模式为默认运行等级</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#37-重启、停止、挂起、休眠系统或使系统进入混合睡眠"><span class="toc-number">6.7.</span> <span class="toc-text">37. 重启、停止、挂起、休眠系统或使系统进入混合睡眠</span></a></li></ol></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">TmoonSite</span>
      </span>
      
    <div class="postdate">
      
        <time datetime="2016-07-19T11:03:52.000Z" itemprop="datePublished">2016-07-19</time>
        
      
    </div>


      

      

    </div>
  </header>
  

  <div class="content" itemprop="articleBody">
    <p>Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。</p>
<p>Systemd是一个系统管理守护进程、工具和库的集合，用于取代System V初始进程。Systemd的功能是用于集中管理和配置类UNIX系统。</p>
<p>在Linux生态系统中，Systemd被部署到了大多数的标准Linux发行版中，只有为数不多的几个发行版尚未部署。Systemd通常是所有其它守护进程的父进程，但并非总是如此。</p>
<p> <em>使用Systemctl管理Linux服务</em></p>
<p>本文旨在阐明在运行systemd的系统上“如何控制系统和服务”。</p>
<h3 id="Systemd初体验和Systemctl基础"><a href="#Systemd初体验和Systemctl基础" class="headerlink" title="Systemd初体验和Systemctl基础"></a>Systemd初体验和Systemctl基础</h3><h4 id="1-首先检查你的系统中是否安装有systemd并确定当前安装的版本"><a href="#1-首先检查你的系统中是否安装有systemd并确定当前安装的版本" class="headerlink" title="1. 首先检查你的系统中是否安装有systemd并确定当前安装的版本"></a>1. 首先检查你的系统中是否安装有systemd并确定当前安装的版本</h4><ol>
<li><code># systemctl --version</code></li>
<li><code>systemd 215</code></li>
<li><code>+PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR</code></li>
</ol>
<p>上例中很清楚地表明，我们安装了215版本的systemd。</p>
<h4 id="2-检查systemd和systemctl的二进制文件和库文件的安装位置"><a href="#2-检查systemd和systemctl的二进制文件和库文件的安装位置" class="headerlink" title="2. 检查systemd和systemctl的二进制文件和库文件的安装位置"></a>2. 检查systemd和systemctl的二进制文件和库文件的安装位置</h4><ol>
<li><code># whereis systemd</code></li>
<li><code>systemd: /usr/lib/systemd /etc/systemd /usr/share/systemd /usr/share/man/man1/systemd.1.gz</code></li>
<li><code># whereis systemctl</code></li>
<li><code>systemctl: /usr/bin/systemctl /usr/share/man/man1/systemctl.1.gz</code></li>
</ol>
<h4 id="3-检查systemd是否运行"><a href="#3-检查systemd是否运行" class="headerlink" title="3. 检查systemd是否运行"></a>3. 检查systemd是否运行</h4><ol>
<li><code># ps -eaf | grep [s]ystemd</code></li>
<li><code>root 1 0 0 16:27 ? 00:00:00 /usr/lib/systemd/systemd --switched-root --system --deserialize 23</code></li>
<li><code>root 444 1 0 16:27 ? 00:00:00 /usr/lib/systemd/systemd-journald</code></li>
<li><code>root 469 1 0 16:27 ? 00:00:00 /usr/lib/systemd/systemd-udevd</code></li>
<li><code>root 555 1 0 16:27 ? 00:00:00 /usr/lib/systemd/systemd-logind</code></li>
<li><code>dbus 556 1 0 16:27 ? 00:00:00 /bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation</code></li>
</ol>
<p> <strong>注意</strong> ：systemd是作为父进程（PID=1）运行的。在上面带（-e）参数的ps命令输出中，选择所有进程，（-a）选择除会话前导外的所有进程，并使用（-f）参数输出完整格式列表（即 -eaf）。</p>
<p>也请注意上例中后随的方括号和例子中剩余部分。方括号表达式是grep的字符类表达式的一部分。</p>
<h4 id="4-分析systemd启动进程"><a href="#4-分析systemd启动进程" class="headerlink" title="4. 分析systemd启动进程"></a>4. 分析systemd启动进程</h4><ol>
<li><code># systemd-analyze</code></li>
<li><code>Startup finished in 487ms (kernel) + 2.776s (initrd) + 20.229s (userspace) = 23.493s</code></li>
</ol>
<h4 id="5-分析启动时各个进程花费的时间"><a href="#5-分析启动时各个进程花费的时间" class="headerlink" title="5. 分析启动时各个进程花费的时间"></a>5. 分析启动时各个进程花费的时间</h4><ol>
<li><code># systemd-analyze blame</code></li>
<li><code>8.565s mariadb.service</code></li>
<li><code>7.991s webmin.service</code></li>
<li><code>6.095s postfix.service</code></li>
<li><code>4.311s httpd.service</code></li>
<li><code>3.926s firewalld.service</code></li>
<li><code>3.780s kdump.service</code></li>
<li><code>3.238s tuned.service</code></li>
<li><code>1.712s network.service</code></li>
<li><code>1.394s lvm2-monitor.service</code></li>
<li><code>1.126s systemd-logind.service</code></li>
<li><code>....</code></li>
</ol>
<h4 id="6-分析启动时的关键链"><a href="#6-分析启动时的关键链" class="headerlink" title="6. 分析启动时的关键链"></a>6. 分析启动时的关键链</h4><ol>
<li><code># systemd-analyze critical-chain</code></li>
<li><code>The time after the unit is active or started is printed after the &quot;@&quot; character.</code></li>
<li><code>The time the unit takes to start is printed after the &quot;+&quot; character.</code></li>
<li><code>multi-user.target @20.222s</code></li>
<li><code>└─mariadb.service @11.657s +8.565s</code></li>
<li><code>└─network.target @11.168s</code></li>
<li><code>└─network.service @9.456s +1.712s</code></li>
<li><code>└─NetworkManager.service @8.858s +596ms</code></li>
<li><code>└─firewalld.service @4.931s +3.926s</code></li>
<li><code>└─basic.target @4.916s</code></li>
<li><code>└─sockets.target @4.916s</code></li>
<li><code>└─dbus.socket @4.916s</code></li>
<li><code>└─sysinit.target @4.905s</code></li>
<li><code>└─systemd-update-utmp.service @4.864s +39ms</code></li>
<li><code>└─auditd.service @4.563s +301ms</code></li>
<li><code>└─systemd-tmpfiles-setup.service @4.485s +69ms</code></li>
<li><code>└─rhel-import-state.service @4.342s +142ms</code></li>
<li><code>└─local-fs.target @4.324s</code></li>
<li><code>└─boot.mount @4.286s +31ms</code></li>
<li><code>└─systemd-fsck@dev-disk-by\x2duuid-79f594ad\x2da332\x2d4730\x2dbb5f\x2d85d19608096</code></li>
<li><code>└─dev-disk-by\x2duuid-79f594ad\x2da332\x2d4730\x2dbb5f\x2d85d196080964.device @4</code></li>
</ol>
<p> <strong>重要</strong> ：Systemctl接受服务（.service），挂载点（.mount），套接口（.socket）和设备（.device）作为单元。</p>
<h4 id="7-列出所有可用单元"><a href="#7-列出所有可用单元" class="headerlink" title="7. 列出所有可用单元"></a>7. 列出所有可用单元</h4><ol>
<li><code># systemctl list-unit-files</code></li>
<li><code>UNIT FILE STATE</code></li>
<li><code>proc-sys-fs-binfmt_misc.automount static</code></li>
<li><code>dev-hugepages.mount static</code></li>
<li><code>dev-mqueue.mount static</code></li>
<li><code>proc-sys-fs-binfmt_misc.mount static</code></li>
<li><code>sys-fs-fuse-connections.mount static</code></li>
<li><code>sys-kernel-config.mount static</code></li>
<li><code>sys-kernel-debug.mount static</code></li>
<li><code>tmp.mount disabled</code></li>
<li><code>brandbot.path disabled</code></li>
<li><code>.....</code></li>
</ol>
<h4 id="8-列出所有运行中单元"><a href="#8-列出所有运行中单元" class="headerlink" title="8. 列出所有运行中单元"></a>8. 列出所有运行中单元</h4><ol>
<li><code># systemctl list-units</code></li>
<li><code>UNIT LOAD ACTIVE SUB DESCRIPTION</code></li>
<li><code>proc-sys-fs-binfmt_misc.automount loaded active waiting Arbitrary Executable File Formats File Syste</code></li>
<li><code>sys-devices-pc...0-1:0:0:0-block-sr0.device loaded active plugged VBOX_CD-ROM</code></li>
<li><code>sys-devices-pc...:00:03.0-net-enp0s3.device loaded active plugged PRO/1000 MT Desktop Adapter</code></li>
<li><code>sys-devices-pc...00:05.0-sound-card0.device loaded active plugged 82801AA AC&#39;97 Audio Controller</code></li>
<li><code>sys-devices-pc...:0:0-block-sda-sda1.device loaded active plugged VBOX_HARDDISK</code></li>
<li><code>sys-devices-pc...:0:0-block-sda-sda2.device loaded active plugged LVM PV Qzyo3l-qYaL-uRUa-Cjuk-pljo-qKtX-VgBQ8</code></li>
<li><code>sys-devices-pc...0-2:0:0:0-block-sda.device loaded active plugged VBOX_HARDDISK</code></li>
<li><code>sys-devices-pl...erial8250-tty-ttyS0.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS0</code></li>
<li><code>sys-devices-pl...erial8250-tty-ttyS1.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS1</code></li>
<li><code>sys-devices-pl...erial8250-tty-ttyS2.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS2</code></li>
<li><code>sys-devices-pl...erial8250-tty-ttyS3.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS3</code></li>
<li><code>sys-devices-virtual-block-dm\x2d0.device loaded active plugged /sys/devices/virtual/block/dm-0</code></li>
<li><code>sys-devices-virtual-block-dm\x2d1.device loaded active plugged /sys/devices/virtual/block/dm-1</code></li>
<li><code>sys-module-configfs.device loaded active plugged /sys/module/configfs</code></li>
<li><code>...</code></li>
</ol>
<h4 id="9-列出所有失败单元"><a href="#9-列出所有失败单元" class="headerlink" title="9. 列出所有失败单元"></a>9. 列出所有失败单元</h4><ol>
<li><code># systemctl --failed</code></li>
<li><code>UNIT LOAD ACTIVE SUB DESCRIPTION</code></li>
<li><code>kdump.service loaded failed failed Crash recovery kernel arming</code></li>
<li><code>LOAD = Reflects whether the unit definition was properly loaded.</code></li>
<li><code>ACTIVE = The high-level unit activation state, i.e. generalization of SUB.</code></li>
<li><code>SUB = The low-level unit activation state, values depend on unit type.</code></li>
<li><code>1 loaded units listed. Pass --all to see loaded but inactive units, too.</code></li>
<li><code>To show all installed unit files use &#39;systemctl list-unit-files&#39;.</code></li>
</ol>
<h4 id="10-检查某个单元（如-cron-service）是否启用"><a href="#10-检查某个单元（如-cron-service）是否启用" class="headerlink" title="10. 检查某个单元（如 cron.service）是否启用"></a>10. 检查某个单元（如 cron.service）是否启用</h4><ol>
<li><code># systemctl is-enabled crond.service</code></li>
<li><code>enabled</code></li>
</ol>
<h4 id="11-检查某个单元或服务是否运行"><a href="#11-检查某个单元或服务是否运行" class="headerlink" title="11. 检查某个单元或服务是否运行"></a>11. 检查某个单元或服务是否运行</h4><ol>
<li><code># systemctl status firewalld.service</code></li>
<li><code>firewalld.service - firewalld - dynamic firewall daemon</code></li>
<li><code>Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled)</code></li>
<li><code>Active: active (running) since Tue 2015-04-28 16:27:55 IST; 34min ago</code></li>
<li><code>Main PID: 549 (firewalld)</code></li>
<li><code>CGroup: /system.slice/firewalld.service</code></li>
<li><code>└─549 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid</code></li>
<li><code>Apr 28 16:27:51 tecmint systemd[1]: Starting firewalld - dynamic firewall daemon...</code></li>
<li><code>Apr 28 16:27:55 tecmint systemd[1]: Started firewalld - dynamic firewall daemon.</code></li>
</ol>
<h3 id="使用Systemctl控制并管理服务"><a href="#使用Systemctl控制并管理服务" class="headerlink" title="使用Systemctl控制并管理服务"></a>使用Systemctl控制并管理服务</h3><h4 id="12-列出所有服务（包括启用的和禁用的）"><a href="#12-列出所有服务（包括启用的和禁用的）" class="headerlink" title="12. 列出所有服务（包括启用的和禁用的）"></a>12. 列出所有服务（包括启用的和禁用的）</h4><ol>
<li><code># systemctl list-unit-files --type=service</code></li>
<li><code>UNIT FILE STATE</code></li>
<li><code>arp-ethers.service disabled</code></li>
<li><code>auditd.service enabled</code></li>
<li><code>autovt@.service disabled</code></li>
<li><code>blk-availability.service disabled</code></li>
<li><code>brandbot.service static</code></li>
<li><code>collectd.service disabled</code></li>
<li><code>console-getty.service disabled</code></li>
<li><code>console-shell.service disabled</code></li>
<li><code>cpupower.service disabled</code></li>
<li><code>crond.service enabled</code></li>
<li><code>dbus-org.fedoraproject.FirewallD1.service enabled</code></li>
<li><code>....</code></li>
</ol>
<h4 id="13-Linux中如何启动、重启、停止、重载服务以及检查服务（如-httpd-service）状态"><a href="#13-Linux中如何启动、重启、停止、重载服务以及检查服务（如-httpd-service）状态" class="headerlink" title="13. Linux中如何启动、重启、停止、重载服务以及检查服务（如 httpd.service）状态"></a>13. Linux中如何启动、重启、停止、重载服务以及检查服务（如 httpd.service）状态</h4><ol>
<li><code># systemctl start httpd.service</code></li>
<li><code># systemctl restart httpd.service</code></li>
<li><code># systemctl stop httpd.service</code></li>
<li><code># systemctl reload httpd.service</code></li>
<li><code># systemctl status httpd.service</code></li>
<li><code>httpd.service - The Apache HTTP Server</code></li>
<li><code>Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)</code></li>
<li><code>Active: active (running) since Tue 2015-04-28 17:21:30 IST; 6s ago</code></li>
<li><code>Process: 2876 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)</code></li>
<li><code>Main PID: 2881 (httpd)</code></li>
<li><code>Status: &quot;Processing requests...&quot;</code></li>
<li><code>CGroup: /system.slice/httpd.service</code></li>
<li><code>├─2881 /usr/sbin/httpd -DFOREGROUND</code></li>
<li><code>├─2884 /usr/sbin/httpd -DFOREGROUND</code></li>
<li><code>├─2885 /usr/sbin/httpd -DFOREGROUND</code></li>
<li><code>├─2886 /usr/sbin/httpd -DFOREGROUND</code></li>
<li><code>├─2887 /usr/sbin/httpd -DFOREGROUND</code></li>
<li><code>└─2888 /usr/sbin/httpd -DFOREGROUND</code></li>
<li><code>Apr 28 17:21:30 tecmint systemd[1]: Starting The Apache HTTP Server...</code></li>
<li><code>Apr 28 17:21:30 tecmint httpd[2881]: AH00558: httpd: Could not reliably determine the server&#39;s fully q...ssage</code></li>
<li><code>Apr 28 17:21:30 tecmint systemd[1]: Started The Apache HTTP Server.</code></li>
<li><code>Hint: Some lines were ellipsized, use -l to show in full.</code></li>
</ol>
<p> <strong>注意</strong> ：当我们使用systemctl的start，restart，stop和reload命令时，我们不会从终端获取到任何输出内容，只有status命令可以打印输出。</p>
<h4 id="14-如何激活服务并在启动时启用或禁用服务（即系统启动时自动启动服务）"><a href="#14-如何激活服务并在启动时启用或禁用服务（即系统启动时自动启动服务）" class="headerlink" title="14. 如何激活服务并在启动时启用或禁用服务（即系统启动时自动启动服务）"></a>14. 如何激活服务并在启动时启用或禁用服务（即系统启动时自动启动服务）</h4><ol>
<li><code># systemctl is-active httpd.service</code></li>
<li><code># systemctl enable httpd.service</code></li>
<li><code># systemctl disable httpd.service</code></li>
</ol>
<h4 id="15-如何屏蔽（让它不能启动）或显示服务（如-httpd-service）"><a href="#15-如何屏蔽（让它不能启动）或显示服务（如-httpd-service）" class="headerlink" title="15. 如何屏蔽（让它不能启动）或显示服务（如 httpd.service）"></a>15. 如何屏蔽（让它不能启动）或显示服务（如 httpd.service）</h4><ol>
<li><code># systemctl mask httpd.service</code></li>
<li><code>ln -s &#39;/dev/null&#39; &#39;/etc/systemd/system/httpd.service&#39;</code></li>
<li><code># systemctl unmask httpd.service</code></li>
<li><code>rm &#39;/etc/systemd/system/httpd.service&#39;</code></li>
</ol>
<h4 id="16-使用systemctl命令杀死服务"><a href="#16-使用systemctl命令杀死服务" class="headerlink" title="16. 使用systemctl命令杀死服务"></a>16. 使用systemctl命令杀死服务</h4><ol>
<li><code># systemctl kill httpd</code></li>
<li><code># systemctl status httpd</code></li>
<li><code>httpd.service - The Apache HTTP Server</code></li>
<li><code>Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)</code></li>
<li><code>Active: failed (Result: exit-code) since Tue 2015-04-28 18:01:42 IST; 28min ago</code></li>
<li><code>Main PID: 2881 (code=exited, status=0/SUCCESS)</code></li>
<li><code>Status: &quot;Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec&quot;</code></li>
<li><code>Apr 28 17:37:29 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti...bled.</code></li>
<li><code>Apr 28 17:37:29 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti...bled.</code></li>
<li><code>Apr 28 17:37:39 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti...bled.</code></li>
<li><code>Apr 28 17:37:39 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti...bled.</code></li>
<li><code>Apr 28 17:37:49 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti...bled.</code></li>
<li><code>Apr 28 17:37:49 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti...bled.</code></li>
<li><code>Apr 28 17:37:59 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti...bled.</code></li>
<li><code>Apr 28 17:37:59 tecmint systemd[1]: httpd.service: Got notification message from PID 2881, but recepti...bled.</code></li>
<li><code>Apr 28 18:01:42 tecmint systemd[1]: httpd.service: control process exited, code=exited status=226</code></li>
<li><code>Apr 28 18:01:42 tecmint systemd[1]: Unit httpd.service entered failed state.</code></li>
<li><code>Hint: Some lines were ellipsized, use -l to show in full.</code></li>
</ol>
<h3 id="使用Systemctl控制并管理挂载点"><a href="#使用Systemctl控制并管理挂载点" class="headerlink" title="使用Systemctl控制并管理挂载点"></a>使用Systemctl控制并管理挂载点</h3><h4 id="17-列出所有系统挂载点"><a href="#17-列出所有系统挂载点" class="headerlink" title="17. 列出所有系统挂载点"></a>17. 列出所有系统挂载点</h4><ol>
<li><code># systemctl list-unit-files --type=mount</code></li>
<li><code>UNIT FILE STATE</code></li>
<li><code>dev-hugepages.mount static</code></li>
<li><code>dev-mqueue.mount static</code></li>
<li><code>proc-sys-fs-binfmt_misc.mount static</code></li>
<li><code>sys-fs-fuse-connections.mount static</code></li>
<li><code>sys-kernel-config.mount static</code></li>
<li><code>sys-kernel-debug.mount static</code></li>
<li><code>tmp.mount disabled</code></li>
</ol>
<h4 id="18-挂载、卸载、重新挂载、重载系统挂载点并检查系统中挂载点状态"><a href="#18-挂载、卸载、重新挂载、重载系统挂载点并检查系统中挂载点状态" class="headerlink" title="18. 挂载、卸载、重新挂载、重载系统挂载点并检查系统中挂载点状态"></a>18. 挂载、卸载、重新挂载、重载系统挂载点并检查系统中挂载点状态</h4><ol>
<li><code># systemctl start tmp.mount</code></li>
<li><code># systemctl stop tmp.mount</code></li>
<li><code># systemctl restart tmp.mount</code></li>
<li><code># systemctl reload tmp.mount</code></li>
<li><code># systemctl status tmp.mount</code></li>
<li><code>tmp.mount - Temporary Directory</code></li>
<li><code>Loaded: loaded (/usr/lib/systemd/system/tmp.mount; disabled)</code></li>
<li><code>Active: active (mounted) since Tue 2015-04-28 17:46:06 IST; 2min 48s ago</code></li>
<li><code>Where: /tmp</code></li>
<li><code>What: tmpfs</code></li>
<li><code>Docs: man:hier(7)</code></li>
<li><code>http://www.freedesktop.org/wiki/Software/systemd/APIFileSystems</code></li>
<li><code>Process: 3908 ExecMount=/bin/mount tmpfs /tmp -t tmpfs -o mode=1777,strictatime (code=exited, status=0/SUCCESS)</code></li>
<li><code>Apr 28 17:46:06 tecmint systemd[1]: Mounting Temporary Directory...</code></li>
<li><code>Apr 28 17:46:06 tecmint systemd[1]: tmp.mount: Directory /tmp to mount over is not empty, mounting anyway.</code></li>
<li><code>Apr 28 17:46:06 tecmint systemd[1]: Mounted Temporary Directory.</code></li>
</ol>
<h4 id="19-在启动时激活、启用或禁用挂载点（系统启动时自动挂载）"><a href="#19-在启动时激活、启用或禁用挂载点（系统启动时自动挂载）" class="headerlink" title="19. 在启动时激活、启用或禁用挂载点（系统启动时自动挂载）"></a>19. 在启动时激活、启用或禁用挂载点（系统启动时自动挂载）</h4><ol>
<li><code># systemctl is-active tmp.mount</code></li>
<li><code># systemctl enable tmp.mount</code></li>
<li><code># systemctl disable tmp.mount</code></li>
</ol>
<h4 id="20-在Linux中屏蔽（让它不能启用）或可见挂载点"><a href="#20-在Linux中屏蔽（让它不能启用）或可见挂载点" class="headerlink" title="20. 在Linux中屏蔽（让它不能启用）或可见挂载点"></a>20. 在Linux中屏蔽（让它不能启用）或可见挂载点</h4><ol>
<li><code># systemctl mask tmp.mount</code></li>
<li><code>ln -s &#39;/dev/null&#39; &#39;/etc/systemd/system/tmp.mount&#39;</code></li>
<li><code># systemctl unmask tmp.mount</code></li>
<li><code>rm &#39;/etc/systemd/system/tmp.mount&#39;</code></li>
</ol>
<h3 id="使用Systemctl控制并管理套接口"><a href="#使用Systemctl控制并管理套接口" class="headerlink" title="使用Systemctl控制并管理套接口"></a>使用Systemctl控制并管理套接口</h3><h4 id="21-列出所有可用系统套接口"><a href="#21-列出所有可用系统套接口" class="headerlink" title="21. 列出所有可用系统套接口"></a>21. 列出所有可用系统套接口</h4><ol>
<li><code># systemctl list-unit-files --type=socket</code></li>
<li><code>UNIT FILE STATE</code></li>
<li><code>dbus.socket static</code></li>
<li><code>dm-event.socket enabled</code></li>
<li><code>lvm2-lvmetad.socket enabled</code></li>
<li><code>rsyncd.socket disabled</code></li>
<li><code>sshd.socket disabled</code></li>
<li><code>syslog.socket static</code></li>
<li><code>systemd-initctl.socket static</code></li>
<li><code>systemd-journald.socket static</code></li>
<li><code>systemd-shutdownd.socket static</code></li>
<li><code>systemd-udevd-control.socket static</code></li>
<li><code>systemd-udevd-kernel.socket static</code></li>
<li><code>11 unit files listed.</code></li>
</ol>
<h4 id="22-在Linux中启动、重启、停止、重载套接口并检查其状态"><a href="#22-在Linux中启动、重启、停止、重载套接口并检查其状态" class="headerlink" title="22. 在Linux中启动、重启、停止、重载套接口并检查其状态"></a>22. 在Linux中启动、重启、停止、重载套接口并检查其状态</h4><ol>
<li><code># systemctl start cups.socket</code></li>
<li><code># systemctl restart cups.socket</code></li>
<li><code># systemctl stop cups.socket</code></li>
<li><code># systemctl reload cups.socket</code></li>
<li><code># systemctl status cups.socket</code></li>
<li><code>cups.socket - CUPS Printing Service Sockets</code></li>
<li><code>Loaded: loaded (/usr/lib/systemd/system/cups.socket; enabled)</code></li>
<li><code>Active: active (listening) since Tue 2015-04-28 18:10:59 IST; 8s ago</code></li>
<li><code>Listen: /var/run/cups/cups.sock (Stream)</code></li>
<li><code>Apr 28 18:10:59 tecmint systemd[1]: Starting CUPS Printing Service Sockets.</code></li>
<li><code>Apr 28 18:10:59 tecmint systemd[1]: Listening on CUPS Printing Service Sockets.</code></li>
</ol>
<h4 id="23-在启动时激活套接口，并启用或禁用它（系统启动时自启动）"><a href="#23-在启动时激活套接口，并启用或禁用它（系统启动时自启动）" class="headerlink" title="23. 在启动时激活套接口，并启用或禁用它（系统启动时自启动）"></a>23. 在启动时激活套接口，并启用或禁用它（系统启动时自启动）</h4><ol>
<li><code># systemctl is-active cups.socket</code></li>
<li><code># systemctl enable cups.socket</code></li>
<li><code># systemctl disable cups.socket</code></li>
</ol>
<h4 id="24-屏蔽（使它不能启动）或显示套接口"><a href="#24-屏蔽（使它不能启动）或显示套接口" class="headerlink" title="24. 屏蔽（使它不能启动）或显示套接口"></a>24. 屏蔽（使它不能启动）或显示套接口</h4><ol>
<li><code># systemctl mask cups.socket</code></li>
<li><code>ln -s &#39;/dev/null&#39; &#39;/etc/systemd/system/cups.socket&#39;</code></li>
<li><code># systemctl unmask cups.socket</code></li>
<li><code>rm &#39;/etc/systemd/system/cups.socket&#39;</code></li>
</ol>
<h3 id="服务的CPU利用率（分配额）"><a href="#服务的CPU利用率（分配额）" class="headerlink" title="服务的CPU利用率（分配额）"></a>服务的CPU利用率（分配额）</h3><h4 id="25-获取当前某个服务的CPU分配额（如httpd）"><a href="#25-获取当前某个服务的CPU分配额（如httpd）" class="headerlink" title="25. 获取当前某个服务的CPU分配额（如httpd）"></a>25. 获取当前某个服务的CPU分配额（如httpd）</h4><ol>
<li><code># systemctl show -p CPUShares httpd.service</code></li>
<li><code>CPUShares=1024</code></li>
</ol>
<p> <strong>注意</strong> ：各个服务的默认CPU分配份额=1024，你可以增加/减少某个进程的CPU分配份额。</p>
<h4 id="26-将某个服务（httpd-service）的CPU分配份额限制为2000-CPUShares"><a href="#26-将某个服务（httpd-service）的CPU分配份额限制为2000-CPUShares" class="headerlink" title="26. 将某个服务（httpd.service）的CPU分配份额限制为2000 CPUShares/"></a>26. 将某个服务（httpd.service）的CPU分配份额限制为2000 CPUShares/</h4><ol>
<li><code># systemctl set-property httpd.service CPUShares=2000</code></li>
<li><code># systemctl show -p CPUShares httpd.service</code></li>
<li><code>CPUShares=2000</code></li>
</ol>
<p> <strong>注意</strong> ：当你为某个服务设置CPUShares，会自动创建一个以服务名命名的目录（如 httpd.service），里面包含了一个名为90-CPUShares.conf的文件，该文件含有CPUShare限制信息，你可以通过以下方式查看该文件：</p>
<ol>
<li><code># vi /etc/systemd/system/httpd.service.d/90-CPUShares.conf</code></li>
<li><code>[Service]</code></li>
<li><code>CPUShares=2000</code></li>
</ol>
<h4 id="27-检查某个服务的所有配置细节"><a href="#27-检查某个服务的所有配置细节" class="headerlink" title="27. 检查某个服务的所有配置细节"></a>27. 检查某个服务的所有配置细节</h4><ol>
<li><code># systemctl show httpd</code></li>
<li><code>Id=httpd.service</code></li>
<li><code>Names=httpd.service</code></li>
<li><code>Requires=basic.target</code></li>
<li><code>Wants=system.slice</code></li>
<li><code>WantedBy=multi-user.target</code></li>
<li><code>Conflicts=shutdown.target</code></li>
<li><code>Before=shutdown.target multi-user.target</code></li>
<li><code>After=network.target remote-fs.target nss-lookup.target systemd-journald.socket basic.target system.slice</code></li>
<li><code>Description=The Apache HTTP Server</code></li>
<li><code>LoadState=loaded</code></li>
<li><code>ActiveState=active</code></li>
<li><code>SubState=running</code></li>
<li><code>FragmentPath=/usr/lib/systemd/system/httpd.service</code></li>
<li><code>....</code></li>
</ol>
<h4 id="28-分析某个服务（httpd）的关键链"><a href="#28-分析某个服务（httpd）的关键链" class="headerlink" title="28. 分析某个服务（httpd）的关键链"></a>28. 分析某个服务（httpd）的关键链</h4><ol>
<li><code># systemd-analyze critical-chain httpd.service</code></li>
<li><code>The time after the unit is active or started is printed after the &quot;@&quot; character.</code></li>
<li><code>The time the unit takes to start is printed after the &quot;+&quot; character.</code></li>
<li><code>httpd.service +142ms</code></li>
<li><code>└─network.target @11.168s</code></li>
<li><code>└─network.service @9.456s +1.712s</code></li>
<li><code>└─NetworkManager.service @8.858s +596ms</code></li>
<li><code>└─firewalld.service @4.931s +3.926s</code></li>
<li><code>└─basic.target @4.916s</code></li>
<li><code>└─sockets.target @4.916s</code></li>
<li><code>└─dbus.socket @4.916s</code></li>
<li><code>└─sysinit.target @4.905s</code></li>
<li><code>└─systemd-update-utmp.service @4.864s +39ms</code></li>
<li><code>└─auditd.service @4.563s +301ms</code></li>
<li><code>└─systemd-tmpfiles-setup.service @4.485s +69ms</code></li>
<li><code>└─rhel-import-state.service @4.342s +142ms</code></li>
<li><code>└─local-fs.target @4.324s</code></li>
<li><code>└─boot.mount @4.286s +31ms</code></li>
<li><code>└─systemd-fsck@dev-disk-by\x2duuid-79f594ad\x2da332\x2d4730\x2dbb5f\x2d85d196080964.service @4.092s +149ms</code></li>
<li><code>└─dev-disk-by\x2duuid-79f594ad\x2da332\x2d4730\x2dbb5f\x2d85d196080964.device @4.092s</code></li>
</ol>
<h4 id="29-获取某个服务（httpd）的依赖性列表"><a href="#29-获取某个服务（httpd）的依赖性列表" class="headerlink" title="29. 获取某个服务（httpd）的依赖性列表"></a>29. 获取某个服务（httpd）的依赖性列表</h4><ol>
<li><code># systemctl list-dependencies httpd.service</code></li>
<li><code>httpd.service</code></li>
<li><code>├─system.slice</code></li>
<li><code>└─basic.target</code></li>
<li><code>├─firewalld.service</code></li>
<li><code>├─microcode.service</code></li>
<li><code>├─rhel-autorelabel-mark.service</code></li>
<li><code>├─rhel-autorelabel.service</code></li>
<li><code>├─rhel-configure.service</code></li>
<li><code>├─rhel-dmesg.service</code></li>
<li><code>├─rhel-loadmodules.service</code></li>
<li><code>├─paths.target</code></li>
<li><code>├─slices.target</code></li>
<li><code>│ ├─-.slice</code></li>
<li><code>│ └─system.slice</code></li>
<li><code>├─sockets.target</code></li>
<li><code>│ ├─dbus.socket</code></li>
<li><code>....</code></li>
</ol>
<h4 id="30-按等级列出控制组"><a href="#30-按等级列出控制组" class="headerlink" title="30. 按等级列出控制组"></a>30. 按等级列出控制组</h4><ol>
<li><code># systemd-cgls</code></li>
<li><code>├─1 /usr/lib/systemd/systemd --switched-root --system --deserialize 23</code></li>
<li><code>├─user.slice</code></li>
<li><code>│ └─user-0.slice</code></li>
<li><code>│ └─session-1.scope</code></li>
<li><code>│ ├─2498 sshd: root@pts/0</code></li>
<li><code>│ ├─2500 -bash</code></li>
<li><code>│ ├─4521 systemd-cgls</code></li>
<li><code>│ └─4522 systemd-cgls</code></li>
<li><code>└─system.slice</code></li>
<li><code>├─httpd.service</code></li>
<li><code>│ ├─4440 /usr/sbin/httpd -DFOREGROUND</code></li>
<li><code>│ ├─4442 /usr/sbin/httpd -DFOREGROUND</code></li>
<li><code>│ ├─4443 /usr/sbin/httpd -DFOREGROUND</code></li>
<li><code>│ ├─4444 /usr/sbin/httpd -DFOREGROUND</code></li>
<li><code>│ ├─4445 /usr/sbin/httpd -DFOREGROUND</code></li>
<li><code>│ └─4446 /usr/sbin/httpd -DFOREGROUND</code></li>
<li><code>├─polkit.service</code></li>
<li><code>│ └─721 /usr/lib/polkit-1/polkitd --no-debug</code></li>
<li><code>....</code></li>
</ol>
<h4 id="31-按CPU、内存、输入和输出列出控制组"><a href="#31-按CPU、内存、输入和输出列出控制组" class="headerlink" title="31. 按CPU、内存、输入和输出列出控制组"></a>31. 按CPU、内存、输入和输出列出控制组</h4><ol>
<li><code># systemd-cgtop</code></li>
<li><code>Path Tasks %CPU Memory Input/s Output/s</code></li>
<li><code>/ 83 1.0 437.8M - -</code></li>
<li><code>/system.slice - 0.1 - - -</code></li>
<li><code>/system.slice/mariadb.service 2 0.1 - - -</code></li>
<li><code>/system.slice/tuned.service 1 0.0 - - -</code></li>
<li><code>/system.slice/httpd.service 6 0.0 - - -</code></li>
<li><code>/system.slice/NetworkManager.service 1 - - - -</code></li>
<li><code>/system.slice/atop.service 1 - - - -</code></li>
<li><code>/system.slice/atopacct.service 1 - - - -</code></li>
<li><code>/system.slice/auditd.service 1 - - - -</code></li>
<li><code>/system.slice/crond.service 1 - - - -</code></li>
<li><code>/system.slice/dbus.service 1 - - - -</code></li>
<li><code>/system.slice/firewalld.service 1 - - - -</code></li>
<li><code>/system.slice/lvm2-lvmetad.service 1 - - - -</code></li>
<li><code>/system.slice/polkit.service 1 - - - -</code></li>
<li><code>/system.slice/postfix.service 3 - - - -</code></li>
<li><code>/system.slice/rsyslog.service 1 - - - -</code></li>
<li><code>/system.slice/system-getty.slice/getty@tty1.service 1 - - - -</code></li>
<li><code>/system.slice/systemd-journald.service 1 - - - -</code></li>
<li><code>/system.slice/systemd-logind.service 1 - - - -</code></li>
<li><code>/system.slice/systemd-udevd.service 1 - - - -</code></li>
<li><code>/system.slice/webmin.service 1 - - - -</code></li>
<li><code>/user.slice/user-0.slice/session-1.scope 3 - - - -</code></li>
</ol>
<h3 id="控制系统运行等级"><a href="#控制系统运行等级" class="headerlink" title="控制系统运行等级"></a>控制系统运行等级</h3><h4 id="32-启动系统救援模式"><a href="#32-启动系统救援模式" class="headerlink" title="32. 启动系统救援模式"></a>32. 启动系统救援模式</h4><ol>
<li><code># systemctl rescue</code></li>
<li><code>Broadcast message from root@tecmint on pts/0 (Wed 2015-04-29 11:31:18 IST):</code></li>
<li><code>The system is going down to rescue mode NOW!</code></li>
</ol>
<h4 id="33-进入紧急模式"><a href="#33-进入紧急模式" class="headerlink" title="33. 进入紧急模式"></a>33. 进入紧急模式</h4><ol>
<li><code># systemctl emergency</code></li>
<li><code>Welcome to emergency mode! After logging in, type &quot;journalctl -xb&quot; to view</code></li>
<li><code>system logs, &quot;systemctl reboot&quot; to reboot, &quot;systemctl default&quot; to try again</code></li>
<li><code>to boot into default mode.</code></li>
</ol>
<h4 id="34-列出当前使用的运行等级"><a href="#34-列出当前使用的运行等级" class="headerlink" title="34. 列出当前使用的运行等级"></a>34. 列出当前使用的运行等级</h4><ol>
<li><code># systemctl get-default</code></li>
<li><code>multi-user.target</code></li>
</ol>
<h4 id="35-启动运行等级5，即图形模式"><a href="#35-启动运行等级5，即图形模式" class="headerlink" title="35. 启动运行等级5，即图形模式"></a>35. 启动运行等级5，即图形模式</h4><ol>
<li><code># systemctl isolate runlevel5.target</code></li>
<li><code>或</code></li>
<li><code># systemctl isolate graphical.target</code></li>
</ol>
<h4 id="36-启动运行等级3，即多用户模式（命令行）"><a href="#36-启动运行等级3，即多用户模式（命令行）" class="headerlink" title="36. 启动运行等级3，即多用户模式（命令行）"></a>36. 启动运行等级3，即多用户模式（命令行）</h4><ol>
<li><code># systemctl isolate runlevel3.target</code></li>
<li><code>或</code></li>
<li><code># systemctl isolate multiuser.target</code></li>
</ol>
<h4 id="36-设置多用户模式或图形模式为默认运行等级"><a href="#36-设置多用户模式或图形模式为默认运行等级" class="headerlink" title="36. 设置多用户模式或图形模式为默认运行等级"></a>36. 设置多用户模式或图形模式为默认运行等级</h4><ol>
<li><code># systemctl set-default runlevel3.target</code></li>
<li><code># systemctl set-default runlevel5.target</code></li>
</ol>
<h4 id="37-重启、停止、挂起、休眠系统或使系统进入混合睡眠"><a href="#37-重启、停止、挂起、休眠系统或使系统进入混合睡眠" class="headerlink" title="37. 重启、停止、挂起、休眠系统或使系统进入混合睡眠"></a>37. 重启、停止、挂起、休眠系统或使系统进入混合睡眠</h4><ol>
<li><code># systemctl reboot</code></li>
<li><code># systemctl halt</code></li>
<li><code># systemctl suspend</code></li>
<li><code># systemctl hibernate</code></li>
<li><code># systemctl hybrid-sleep</code></li>
</ol>
<p>对于不知运行等级为何物的人，说明如下。</p>
<ul>
<li>Runlevel 0 : 关闭系统</li>
<li>Runlevel 1 : 救援？维护模式</li>
<li>Runlevel 3 : 多用户，无图形系统</li>
<li>Runlevel 4 : 多用户，无图形系统</li>
<li>Runlevel 5 : 多用户，图形化系统</li>
<li>Runlevel 6 : 关闭并重启机器</li>
</ul>
<p>到此为止吧。保持连线，进行评论。别忘了在下面的评论中为我们提供一些有价值的反馈哦。喜欢我们、与我们分享，求扩散。</p>

  </div>
</article>



        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">Home</a></li>
         
          <li><a href="/about/">About</a></li>
         
          <li><a href="/archives/">Writing</a></li>
         
          <li><a href="/projects_url">Projects</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#Systemd初体验和Systemctl基础"><span class="toc-number">1.</span> <span class="toc-text">Systemd初体验和Systemctl基础</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-首先检查你的系统中是否安装有systemd并确定当前安装的版本"><span class="toc-number">1.1.</span> <span class="toc-text">1. 首先检查你的系统中是否安装有systemd并确定当前安装的版本</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-检查systemd和systemctl的二进制文件和库文件的安装位置"><span class="toc-number">1.2.</span> <span class="toc-text">2. 检查systemd和systemctl的二进制文件和库文件的安装位置</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-检查systemd是否运行"><span class="toc-number">1.3.</span> <span class="toc-text">3. 检查systemd是否运行</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-分析systemd启动进程"><span class="toc-number">1.4.</span> <span class="toc-text">4. 分析systemd启动进程</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-分析启动时各个进程花费的时间"><span class="toc-number">1.5.</span> <span class="toc-text">5. 分析启动时各个进程花费的时间</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#6-分析启动时的关键链"><span class="toc-number">1.6.</span> <span class="toc-text">6. 分析启动时的关键链</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#7-列出所有可用单元"><span class="toc-number">1.7.</span> <span class="toc-text">7. 列出所有可用单元</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#8-列出所有运行中单元"><span class="toc-number">1.8.</span> <span class="toc-text">8. 列出所有运行中单元</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#9-列出所有失败单元"><span class="toc-number">1.9.</span> <span class="toc-text">9. 列出所有失败单元</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#10-检查某个单元（如-cron-service）是否启用"><span class="toc-number">1.10.</span> <span class="toc-text">10. 检查某个单元（如 cron.service）是否启用</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#11-检查某个单元或服务是否运行"><span class="toc-number">1.11.</span> <span class="toc-text">11. 检查某个单元或服务是否运行</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#使用Systemctl控制并管理服务"><span class="toc-number">2.</span> <span class="toc-text">使用Systemctl控制并管理服务</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#12-列出所有服务（包括启用的和禁用的）"><span class="toc-number">2.1.</span> <span class="toc-text">12. 列出所有服务（包括启用的和禁用的）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#13-Linux中如何启动、重启、停止、重载服务以及检查服务（如-httpd-service）状态"><span class="toc-number">2.2.</span> <span class="toc-text">13. Linux中如何启动、重启、停止、重载服务以及检查服务（如 httpd.service）状态</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#14-如何激活服务并在启动时启用或禁用服务（即系统启动时自动启动服务）"><span class="toc-number">2.3.</span> <span class="toc-text">14. 如何激活服务并在启动时启用或禁用服务（即系统启动时自动启动服务）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#15-如何屏蔽（让它不能启动）或显示服务（如-httpd-service）"><span class="toc-number">2.4.</span> <span class="toc-text">15. 如何屏蔽（让它不能启动）或显示服务（如 httpd.service）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#16-使用systemctl命令杀死服务"><span class="toc-number">2.5.</span> <span class="toc-text">16. 使用systemctl命令杀死服务</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#使用Systemctl控制并管理挂载点"><span class="toc-number">3.</span> <span class="toc-text">使用Systemctl控制并管理挂载点</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#17-列出所有系统挂载点"><span class="toc-number">3.1.</span> <span class="toc-text">17. 列出所有系统挂载点</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#18-挂载、卸载、重新挂载、重载系统挂载点并检查系统中挂载点状态"><span class="toc-number">3.2.</span> <span class="toc-text">18. 挂载、卸载、重新挂载、重载系统挂载点并检查系统中挂载点状态</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#19-在启动时激活、启用或禁用挂载点（系统启动时自动挂载）"><span class="toc-number">3.3.</span> <span class="toc-text">19. 在启动时激活、启用或禁用挂载点（系统启动时自动挂载）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#20-在Linux中屏蔽（让它不能启用）或可见挂载点"><span class="toc-number">3.4.</span> <span class="toc-text">20. 在Linux中屏蔽（让它不能启用）或可见挂载点</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#使用Systemctl控制并管理套接口"><span class="toc-number">4.</span> <span class="toc-text">使用Systemctl控制并管理套接口</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#21-列出所有可用系统套接口"><span class="toc-number">4.1.</span> <span class="toc-text">21. 列出所有可用系统套接口</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#22-在Linux中启动、重启、停止、重载套接口并检查其状态"><span class="toc-number">4.2.</span> <span class="toc-text">22. 在Linux中启动、重启、停止、重载套接口并检查其状态</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#23-在启动时激活套接口，并启用或禁用它（系统启动时自启动）"><span class="toc-number">4.3.</span> <span class="toc-text">23. 在启动时激活套接口，并启用或禁用它（系统启动时自启动）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#24-屏蔽（使它不能启动）或显示套接口"><span class="toc-number">4.4.</span> <span class="toc-text">24. 屏蔽（使它不能启动）或显示套接口</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#服务的CPU利用率（分配额）"><span class="toc-number">5.</span> <span class="toc-text">服务的CPU利用率（分配额）</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#25-获取当前某个服务的CPU分配额（如httpd）"><span class="toc-number">5.1.</span> <span class="toc-text">25. 获取当前某个服务的CPU分配额（如httpd）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#26-将某个服务（httpd-service）的CPU分配份额限制为2000-CPUShares"><span class="toc-number">5.2.</span> <span class="toc-text">26. 将某个服务（httpd.service）的CPU分配份额限制为2000 CPUShares&#x2F;</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#27-检查某个服务的所有配置细节"><span class="toc-number">5.3.</span> <span class="toc-text">27. 检查某个服务的所有配置细节</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#28-分析某个服务（httpd）的关键链"><span class="toc-number">5.4.</span> <span class="toc-text">28. 分析某个服务（httpd）的关键链</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#29-获取某个服务（httpd）的依赖性列表"><span class="toc-number">5.5.</span> <span class="toc-text">29. 获取某个服务（httpd）的依赖性列表</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#30-按等级列出控制组"><span class="toc-number">5.6.</span> <span class="toc-text">30. 按等级列出控制组</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#31-按CPU、内存、输入和输出列出控制组"><span class="toc-number">5.7.</span> <span class="toc-text">31. 按CPU、内存、输入和输出列出控制组</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#控制系统运行等级"><span class="toc-number">6.</span> <span class="toc-text">控制系统运行等级</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#32-启动系统救援模式"><span class="toc-number">6.1.</span> <span class="toc-text">32. 启动系统救援模式</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#33-进入紧急模式"><span class="toc-number">6.2.</span> <span class="toc-text">33. 进入紧急模式</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#34-列出当前使用的运行等级"><span class="toc-number">6.3.</span> <span class="toc-text">34. 列出当前使用的运行等级</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#35-启动运行等级5，即图形模式"><span class="toc-number">6.4.</span> <span class="toc-text">35. 启动运行等级5，即图形模式</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#36-启动运行等级3，即多用户模式（命令行）"><span class="toc-number">6.5.</span> <span class="toc-text">36. 启动运行等级3，即多用户模式（命令行）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#36-设置多用户模式或图形模式为默认运行等级"><span class="toc-number">6.6.</span> <span class="toc-text">36. 设置多用户模式或图形模式为默认运行等级</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#37-重启、停止、挂起、休眠系统或使系统进入混合睡眠"><span class="toc-number">6.7.</span> <span class="toc-text">37. 重启、停止、挂起、休眠系统或使系统进入混合睡眠</span></a></li></ol></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/" target="_blank" rel="noopener"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&text=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。" target="_blank" rel="noopener"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&title=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。" target="_blank" rel="noopener"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&is_video=false&description=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。" target="_blank" rel="noopener"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。&body=Check out this article: http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&title=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。" target="_blank" rel="noopener"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&title=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。" target="_blank" rel="noopener"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&title=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。" target="_blank" rel="noopener"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&title=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。" target="_blank" rel="noopener"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&name=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。&description=" target="_blank" rel="noopener"><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://news.ycombinator.com/submitlink?u=http://yoursite.com/2016/07/19/Systemctl%E6%98%AF%E4%B8%80%E4%B8%AAsystemd%E5%B7%A5%E5%85%B7%EF%BC%8C%E4%B8%BB%E8%A6%81%E8%B4%9F%E8%B4%A3%E6%8E%A7%E5%88%B6systemd%E7%B3%BB%E7%BB%9F%E5%92%8C%E6%9C%8D%E5%8A%A1%E7%AE%A1%E7%90%86%E5%99%A8%E3%80%82/&t=Systemctl是一个systemd工具，主要负责控制systemd系统和服务管理器。" target="_blank" rel="noopener"><i class="fab fa-hacker-news fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> Menu</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> TOC</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> Share</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> Top</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy; 2020 Tmoonlight
  </div>
  <div class="footer-right">
    <nav>
      <ul>
         
          <li><a href="/">Home</a></li>
         
          <li><a href="/about/">About</a></li>
         
          <li><a href="/archives/">Writing</a></li>
         
          <li><a href="/projects_url">Projects</a></li>
        
      </ul>
    </nav>
  </div>
</footer>

    </div>
    <!-- styles -->

<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">


<link rel="stylesheet" href="/lib/justified-gallery/css/justifiedGallery.min.css">


    <!-- jquery -->

<script src="/lib/jquery/jquery.min.js"></script>


<script src="/lib/justified-gallery/js/jquery.justifiedGallery.min.js"></script>

<!-- clipboard -->

  
<script src="/lib/clipboard/clipboard.min.js"></script>

  <script type="text/javascript">
  $(function() {
    // copy-btn HTML
    var btn = "<span class=\"btn-copy tooltipped tooltipped-sw\" aria-label=\"Copy to clipboard!\">";
    btn += '<i class="far fa-clone"></i>';
    btn += '</span>'; 
    // mount it!
    $(".highlight table").before(btn);
    var clip = new ClipboardJS('.btn-copy', {
      text: function(trigger) {
        return Array.from(trigger.nextElementSibling.querySelectorAll('.code')).reduce((str,it)=>str+it.innerText+'\n','')
      }
    });
    clip.on('success', function(e) {
      e.trigger.setAttribute('aria-label', "Copied!");
      e.clearSelection();
    })
  })
  </script>


<script src="/js/main.js"></script>

<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

<!-- Disqus Comments -->


</body>
</html>
